;
(function($) {
    /**
     * 将对象复制到另一个对象中并返回新的构造函数
     * @param object1 基础类
     * @param object2 扩展类
     * @return
     */

    function extend(object1, object2) {
        var _F = function() {
            for (var i in this) {
                if ($.isPlainObject(this[i]) && i != '_super' && 'initial' in this[i]) {
                    this[i]['_parent'] = this;
                }
            }
            this._super && this._super.initial && this._super.initial.apply(this, arguments);
            this.initial && this.initial.apply(this, arguments);
        };
        if ($.isPlainObject(object1)) {
            for (var i in object1) {
                _F.prototype[i] = object1[i];
            }
            arguments.length > 1 && (_F.prototype._super = object1);
        }
        if ($.isPlainObject(object2)) {
            for (var i in object2) {
                _F.prototype[i] = object2[i];
            }
            if (!('initial' in object2)) {
                _F.prototype['initial'] = null;
            }
        }
        return _F;
    }

    function calendar(options) {
        if (!(this instanceof calendar)) {
            return new calendar(options);
        }
        var _mode = null,
            _object = null;
        if ($.isPlainObject(options)) {
            _mode = options['mode'];
            delete options['mode'];
        }
        _mode = $.inArray(_mode, calendar.modeList) >= 0 ? _mode : 'date';
        _object = new calendar[_mode + 'Picker'](options);
        _object.mode = _mode;
        return _object;
    }
    //支持的模式列表
    calendar.modeList = ['year', 'month', 'date', 'time'];
    //切换构造类
    calendar.switcher = extend({
        initial: function(style) {
            var _self = this;
            //设置面板样式名
            this.style = style || 'think-calendar-switch';
            //创建切换面板
            this.switchPanelElement = $('<div/>').addClass(this.style);
            //创建显示值元素
            this.switchValueElement = $('<b class="' + this.style + '-value"></b>').appendTo(this.switchPanelElement);
            //创建向前切换元素
            this.switchPrevElement = $('<b class="' + this.style + '-prev">&lt;</b>').prependTo(this.switchPanelElement);
            //创建向后切换元素
            this.switchNextElement = $('<b class="' + this.style + '-next">&gt;</b>').appendTo(this.switchPanelElement);
            //绑定向前切换事件
            this.switchPrevElement.click(function() {
                if (!_self.switchPrevDisabled) {
                    $(_self).triggerHandler('onPrev', $(this));
                }
            });
            //绑定向后切换事件
            this.switchNextElement.click(function() {
                if (!_self.switchNextDisabled) {
                    $(_self).triggerHandler('onNext', $(this));
                }
            });
            //绑定点击值事件
            this.switchValueElement.click(function() {
                if (!_self.switchChangeDisabled) {
                    $(_self).triggerHandler('onChange', $(this));
                }
            });
        },
        /**
         * 绑定事件
         * @return switcher
         */
        on: function(name, fun) {
            $(this).bind(name, fun);
            return this;
        },
        /**
         * 卸载事件
         * @return switcher
         */
        off: function(name) {
            $(this).unbind(name, fun);
            return this;
        },
        /**
         * 设置或获取显示值
         * @return switcher
         */
        value: function(text) {
            this.switchValueElement.text(text);
            return this;
        },
        /**
         * 设置是否禁止切换
         * @param role 切换的角色 1为向前切换元素，2为向后切换元素, 0全部
         * @param status 是否禁止切换开关
         * @return maxDate
         */
        disabled: function(role, status) {
            if (!$.isNumeric(role)) {
                status = role;
                role = 0;
            }
            status = status ? true : false;
            switch (role) {
                case 0:
                    this.switchPrevDisabled = status;
                    status ? this.switchPrevElement.addClass('' + this.style + '-disabled') : this.switchPrevElement.removeClass('' + this.style + '-disabled');
                    break;
                case 1:
                    this.switchNextDisabled = status;
                    status ? this.switchNextElement.addClass('' + this.style + '-disabled') : this.switchNextElement.removeClass('' + this.style + '-disabled');
                    break;
                case 2:
                    this.switchChangeDisabled = status;
                    status ? this.switchValueElement.addClass('' + this.style + '-disabled') : this.switchValueElement.removeClass('' + this.style + '-disabled');
                    break;
            }
            return this;
        },
        /**
         * 获取html元素
         * @return switchPanelElement
         */
        getHtml: function(text) {
            return this.switchPanelElement;
        },
        /**
         * 销毁实例
         * @return void
         */
        destroy: function() {

        }
    });
    //选择年份构造类
    calendar.yearPicker = extend({
        _options: {
            style: 'think-yearpicker',
            currentYear: new Date(), //当前年分
            maxYear: null, //最大选择年份
            minYear: null, //最小选择年份
            invalidYear: null, //无效年份
            switchPanel: true, //是否配置切换面板
            appendTo: 'body', //添加到指定元素内
            onSelect: null, //选择年份触发回调函数
            onChange: null, //当选择面板发生改变时触发
            onCreate: null //初始化完成触发函数
        },
        initial: function(options) {
            var _self = this;
            this.options = $.extend({}, this._options, options);
            //记录原始年份
            this.origYear = this._reviseYear(this.options.currentYear);
            //记录父级容器元素
            this.appendToElement = $(this.options.appendTo);
            //创建月份面板元素
            this.yearPanelElement = $('<div/>').addClass(this._options.style).addClass(this.options.style);
            //创建月份选择面板元素
            this.yearSelectElement = $('<div class="think-yearpicker-select"></div>').appendTo(this.yearPanelElement);
            //绑定选择年份事件
            this.yearPanelElement.delegate('.think-yearpicker-item', 'click', function() {
                _self.selected(_self._selectRange[_self.yearOptionElement.index($(this))]);
            });
            //绑定自定义事件
            this.on('onSelect', this.options.onSelect);
            this.on('onChange', this.options.onChange);
            //选中目标年份
            this.selected(this.origYear);
            //初始安装切换面板
            this.switchPanel(this.options.switchPanel);
            //将年份面板添加到父级容器中
            this.yearPanelElement.appendTo(this.appendToElement);
        },
        //创建选择面板
        _createSelectPanel: function(years) {
            var _panel = '';
            var _length = years.length;
            var _start = years[0] - 1;
            var _end = years[_length - 1] + 1;
            years.unshift(_start);
            years.push(_end);
            _panel += '<table>';
            _panel += '<tr>';
            for (var i = 1; i <= years.length; i++) {
                _panel += '<td><span class="think-yearpicker-item' + (years[i - 1] == _start || years[i - 1] == _end ? ' think-yearpicker-otheryear' : '') + '">' + years[i - 1] + '</span></td>';
                (!(i % 4) && i != 12) && (_panel += '</tr><tr>');
            }
            _panel += '</tr>';
            return _panel;
        },
        //安装或卸载切换面板
        switchPanel: function(status) {
            var _self = this,
                _status = typeof status == 'undefined' ? true : status ? true : false;
            if (_status && !this.switchHander) {
                this.switchHander = new calendar.switcher('think-yearpicker-switch');
                this.yearPanelElement.prepend(this.switchHander.getHtml());
                this.switchHander.on('onPrev', function(object) {
                    _self.prevRange();
                });
                this.switchHander.on('onNext', function(object) {
                    _self.nextRange();
                });
                this.on('onSelect', function() {
                    _self.switchHander.value(_self._selectRange[1] + '-' + _self._selectRange[_self._selectRange.length - 2]);
                });
                this.switchHander.value(this._selectRange[1] + '-' + this._selectRange[this._selectRange.length - 2]);
            } else {
                this.switchHander && this.switchHander.destroy();
            }
        },
        /**
         * 切换到目标年份范围选择面板
         * @return year
         */
        targetRange: function(year) {
            var _year = this._reviseYear(year);
            var _range = this._getRangeYear(_year);
            var _panel = $(this._createSelectPanel(_range));
            var _index = $.inArray(this._selectedYear, _range);
            this._currentYear = year;
            this.yearSelectElement.html(_panel);
            this.yearOptionElement = _panel.find('.think-yearpicker-item');
            this._selectRange = _range;
            _index >= 0 && this.yearOptionElement.eq(_index).addClass('think-yearpicker-selected');
            $(this).trigger('onChange');
            return this;
        },
        /**
         * 获取当前面板选择范围
         * @return range
         */
        getSelectRange: function() {
            return this._selectRange;
        },
        /**
         * 切换到上一组年份范围选择面板
         * @return year
         */
        prevRange: function() {
            return this.targetRange(this._currentYear -= 10);
        },
        /**
         * 切换到下一组年份范围选择面板
         * @return year
         */
        nextRange: function() {
            return this.targetRange(this._currentYear += 10);
        },
        /**
         * 设置或返回禁用状态
         * @param status{Number} 禁用状态
         * @return year
         */
        disabled: function() {

        },
        /**
         * 设置或返回最大选择年份
         * @param number{Number} 最大值
         * @return year
         */
        maxYaer: function() {

        },
        /**
         * 设置或返回最小选择年份
         * @param number{Number} 最小值
         * @return year
         */
        minYaer: function() {

        },
        /**
         * 设置或返回无效年份
         * @param number{Array|Number} 无效年份
         * @return year
         */
        invalidYear: function() {

        },
        /**
         * 设置或获取选中年份
         * @param year{Number} 年份
         * @return year
         */
        selected: function(year) {
            if (typeof year != 'undefined') {
                this._selectedYear = this._reviseYear(year);
                this.targetRange(this._selectedYear);
                this.yearOptionElement.removeClass('think-yearpicker-selected');
                this.yearOptionElement.eq($.inArray(this._selectedYear, this._selectRange)).addClass('think-yearpicker-selected');
                $(this).trigger('onSelect');
            } else {
                return this._selectedYear;
            }
            return this;
        },
        /**
         * 根据年份获取年份范围列表
         * @param year{Number} 起始年份
         * @param length{Number} 横跨长度
         * @return data
         */
        _getRangeYear: function(year) {
            var _year = year,
                _length = 10,
                _modulo = _year % _length,
                _start = _year - _modulo,
                _end = _start + _length,
                _result = [];
            for (var i = _start; i < _end; i++) {
                _result.push(i);
            }
            return _result;
        },
        /**
         * 校正年份
         * @param year{Number} 年份
         * @return year
         */
        _reviseYear: function(year) {
            var _type = $.type(year),
                _date = year;
            if (_type != 'date') {
                _date = new Date();
                _type == 'number' && _date.setFullYear(parseInt(year));
            }
            return _date.getFullYear();
        },
        //绑定事件
        on: function(name, fun) {
            $(this).bind(name, fun);
            return this;
        },
        //卸载事件
        off: function(name) {
            $(this).unbind(name, fun);
            return this;
        }
    });
    //选择月份构造类
    calendar.monthPicker = extend({
        _options: {
            style: 'think-monthpicker',
            currentMonth: new Date(), //当前选中日期
            appendTo: 'body', //指定父级容器选择器或元素
            lang: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            switchPanel: true, //是否安装切换面板
            maxDate: null, //最大选择日期
            minDate: null, //最小选择日期
            onSelect: null, //选择月份时相应事件
            onChange: null, //选择面板发生改变时触发事件
            onCreate: null //组件创建完成触发事件
        },
        initial: function(options) {
            var _self = this;
            this.options = $.extend({}, this._options, options);
            //记录原始日期
            this.origDate = calendar.changeDate(this.options.currentMonth);
            //记录选择列表数据
            this._selectData = [];
            //记录最大选择日期
            this._maxDate = this.options.maxDate;
            //记录最小选择日期
            this._minDate = this.options.minDate;
            //记录选中的日期
            this._selectedDate = new Date(this.origDate.getTime());
            //记录父级容器元素
            this.appendToElement = $(this.options.appendTo);
            //创建月份面板元素
            this.monthPanelElement = $('<div/>').addClass(this._options.style).addClass(this.options.style);
            //创建月份选择面板元素
            this.monthSelectElement = $('<div class="think-monthpicker-select"></div>').appendTo(this.monthPanelElement);
            //绑定选择日期事件
            this.monthSelectElement.delegate('.think-monthpicker-item', 'click', function() {
                _self.selected(_self._currentYear, _self.monthOptionElement.index($(this)));
            });
            this.on('onSelect', this.options.onSelect);
            this.on('onChange', this.options.onChange);
            //初始安装切换面板
            this.switchPanel(this.options.switchPanel);
            //初始切换到指定日期
            this.targetYear(this.origDate.getFullYear());
            //初始选中指定日期
            this.selected(this.origDate.getFullYear(), this.origDate.getMonth());
            //将月份面板添加到父级容器中
            this.monthPanelElement.appendTo(this.appendToElement);
            $.isFunction(this.options.onCreate) && this.options.onCreate.call(this);
        },
        //创建选择面板
        _createSelectPanel: function() {
            var _panel = '';
            _panel += '<table>';
            _panel += '<tr>';
            for (var i = 1; i <= 12; i++) {
                _panel += '<td><span class="think-monthpicker-item">' + (this.options.lang[i - 1]) + '</span></td>';
                (!(i % 4) && i != 12) && (_panel += '</tr><tr>');
            }
            _panel += '</tr>';
            return _panel;
        },
        //安装或卸载切换面板
        switchPanel: function(status) {
            var _self = this,
                _status = typeof status == 'undefined' ? true : status ? true : false;
            if (_status && !this.switchHander) {
                this.switchHander = new calendar.switcher('think-monthpicker-switch');
                this.monthPanelElement.prepend(this.switchHander.getHtml());
                this.switchHander.on('onPrev', function(object) {
                    _self.prevYear();
                });
                this.switchHander.on('onNext', function(object) {
                    _self.nextYear();
                });
                this.on('onChange', function() {
                    this.switchHander.value(this._currentYear);
                });
            } else {
                this.switchHander && this.switchHander.destroy();
            }
        },
        //切换到指定年
        targetYear: function(year) {
            var _self = this,
                _year = parseInt(year);
            if ($.isNumeric(_year)) {
                if (!this._currentYear || this._currentYear != year) {
                    var _panel = $(this._createSelectPanel());
                    this.monthOptionElement = _panel.find('.think-monthpicker-item');
                    this.monthSelectElement.html(_panel);
                    this._selectData = [];
                    this._currentYear = year;
                    this.monthOptionElement.each(function(i, v) {
                        _self._selectData.push({
                            'element': $(this),
                            'year': _self._currentYear,
                            'month': i,
                            'disabled': false
                        });
                    });
                }
                if (this._selectedDate.getFullYear() == year) {
                    this.monthOptionElement.removeClass('think-monthpicker-selected');
                    this.monthOptionElement.eq(this._selectedDate.getMonth()).addClass('think-monthpicker-selected');
                }
                this.maxDate(this._maxDate);
                this.minDate(this._minDate);
                $(this).triggerHandler('onChange', $(this));
            }
            return this;
        },
        //切换到上一年
        prevYear: function() {
            return this.targetYear(this._currentYear - 1);
        },
        //切换到下一年
        nextYear: function() {
            return this.targetYear(this._currentYear + 1);
        },
        //获取或设置当前选中日期
        selected: function(year, month) {
            if ($.isNumeric(year) && $.isNumeric(month)) {
                if (!this.invalid(year, month)) {
                    var _year = parseInt(year);
                    var _month = parseInt(month);
                    this._selectedDate.setFullYear(_year);
                    _month = Math.max(0, _month);
                    _month = Math.min(_month, 11);
                    this._selectedDate.setMonth(_month);
                    var _currentYear = this._selectedDate.getFullYear();
                    this.targetYear(_currentYear);
                    $(this).triggerHandler('onSelect', $(this));
                }
            } else {
                return this._selectedDate;
            }
            return this;
        },
        //设置最大选择日期
        maxDate: function(date) {
            if (typeof date != 'undefined') {
                if (date) {
                    this._maxDate = calendar.changeDate(date);
                    var _maxYear = this._maxDate.getFullYear();
                    var _maxMonth = this._maxDate.getMonth();
                    var _length = 11 - _maxMonth;
                    if (this._currentYear > _maxYear) {
                        for (var i = 0; i <= 11; i++) {
                            this.invalid(this._currentYear, i, true);
                        }
                    } else if (this._currentYear == _maxYear) {
                        for (var i = 0; i <= 11; i++) {
                            this.invalid(this._currentYear, _maxMonth + i, true);
                        }
                    }
                } else {
                    this._maxDate = null;
                }
            } else {
                return this._maxDate;
            }
            return this;
        },
        //设置最小选择日期
        minDate: function(date) {

        },
        //获取当前面板显示的选择年份
        getPanelYear: function() {
            return this._currentYear;
        },
        //设置或获取指定日期是否无效
        invalid: function(year, month, status) {
            var _self = this,
                _status = typeof status == 'undefined' ? null : status ? true : false;
            if ($.type(_status) == 'boolean') {
                for (var i = 0; i < this._selectData.length; i++) {
                    if (this._selectData[i]['year'] == year && this._selectData[i]['month'] == month) {
                        _self._selectData[i]['disabled'] = _status;
                        _status ?
                            _self._selectData[i]['element'].addClass('think-monthpicker-item-disabled') :
                            _self._selectData[i]['element'].removeClass('think-monthpicker-item-disabled');
                        break;
                    }
                }
            } else {
                if ($.type(this._maxDate) == 'date') {
                    var _maxYear = this._maxDate.getFullYear(),
                        _maxMonth = this._maxDate.getMonth();
                    if (year > _maxYear) {
                        return true;
                    } else if (year == _maxYear && month >= _maxMonth) {
                        return true;
                    } else {
                        return false;
                    }
                }
                return false;
            }
        },
        //绑定事件
        on: function(name, fun) {
            $(this).bind(name, fun);
            return this;
        },
        //卸载事件
        off: function(name) {
            $(this).unbind(name, fun);
            return this;
        }
    });
    //选择日期构造类
    calendar.datePicker = extend({
        _buttons: [{
            name: 'clear',
            value: '清除',
            func: function(calendar, button) {
                button.click(function() {
                    calendar.clear();
                });
            }
        }, {
            name: 'apply',
            value: '今天',
            func: function(calendar, button) {
                button.click(function() {
                    calendar.today();
                });
            }
        }, ],
        _options: {
            style: 'think-datepicker', //设置样式名称
            currentDate: new Date(), //当前日期
            maxDate: null, //最大选择日期
            minDate: null, //最小选择日期
            invalidDate: null, //无效日期["Y>2014","M=12","D=45"]
            enableDate: null, //有效日期
            multiple: false, //是否允许多选
            unique: false, //至少选择一项
            format: 'YYYY-MM-DD hh:mm:ss', //格式化方式
            lang: { //语言包配置
                weeks: ['日', '一', '二', '三', '四', '五', '六'],
                months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
            },
            button: ['clear', 'apply'], //按钮配置
            showTime: true, //是否显示时间设置
            isFixed: false, //是否固定选择面板
            appendTo: 'body', //添加到指定元素
            praseData: null, //解析日期选择项方法
            onChange: null, //值发生改变时触发事件
            onSelect: null, //选择日期时触发事件
            onSwitch: null, //日历面板切换时触发事件
            onCreate: null //控件创建完成触发事件
        },
        initial: function(options) {
            var _self = this;
            this.options = $.extend(true, {}, this._options, options);
            //记录样式名称
            this._styleName = calendar.getClass(this._options.style, this.options.style);
            //记录样式名前缀
            this._stylePrefix = this._styleName.split(' ')[0];
            //记录原始日期
            this.origDate = calendar.changeDate(this.options.currentDate);
            //记录按钮列表
            this._buttonList = [];
            //记录选中日期列表
            this._selectedDate = [];
            //记录当前选择面板禁用的日期
            this._disabledDate = [];
            //记录当前选择面板
            this._currentPanel = 'date';
            //初始记录最大选择日期
            this._maxDate = this.options.maxDate;
            //记录面板追加到指定的容器元素
            this.appendToElement = this.options.appendTo ? $(this.options.appendTo) : $('body');
            //创建日期面板元素
            this.datePanelElement = $('<div/>').addClass(this._styleName);
            //创建日期集合元素
            this.dateWrapElement = $('<div class="'+this._stylePrefix+'-wrap"></div>').appendTo(this.datePanelElement);
            //创建日期主面板元素
            this.dateMainElement = $('<div class="'+this._stylePrefix+'-main"></div>').appendTo(this.dateWrapElement);
            //创建日期选择面板元素
            this.dateSelectElement = $('<div class="'+this._stylePrefix+'-date"></div>');
            //实例化切换类
            this.switchHander = new calendar.switcher(''+this._stylePrefix+'-switch');
            //将切换面板添加到日期面板中
            this.datePanelElement.prepend(this.switchHander.getHtml());
            //设置选择方式
            this.multiple(this.options.multiple);
            //绑定向前切换日期操作
            this.switchHander.on('onPrev', function() {
                _self._updatePanelValue('prev');
            });
            //绑定向后切换日期操作
            this.switchHander.on('onNext', function() {
                _self._updatePanelValue('next');
            });
            //绑定点击当前值操作
            this.switchHander.on('onChange', function() {
                if (_self._currentPanel == 'date') {
                    _self._currentPanel = 'month';
                } else if (_self._currentPanel == 'month') {
                    _self._currentPanel = 'year';
                } else if (_self._currentPanel == 'year') {
                    _self._currentPanel = 'date';
                }
                _self._switchPanel(_self._currentPanel);
            });
            //绑定选中日期操作
            this.dateSelectElement.delegate('.'+this._stylePrefix+'-date-day', 'click', function() {
                var _date = _self._selectData[_self.dateOptionElement.index($(this))]['date'],
                    _status = _self.isSelected(_date);
                _self.selected(_date, _self._isMultiple ? !_status : true);
            });
            //初始绑定自定义事件
            this.on('onSelect', this.options.onSelect);
            this.on('onSwitch', this.options.onSwitch);
            this.on('onChange', this.options.onChange);
            //初始设置固定选择状态
            this.fixedType(this.options.isFixed);
            //初始切换到指定日期
            this.targetDate(new Date(this.origDate.getTime()));
            //初始选中指定日期
            this._selected(new Date(this.origDate.getTime()), true);
            //将日期选择面板添加到日期面板元素中
            this.dateSelectElement.appendTo(this.dateMainElement);
            //初始设置是否需要时间控件
            this.showTime(this.options.showTime);
            //初始新增操作按钮
            this.addButton(this.options.button);
            //将日期面板元素添加到指定容器中
            this.datePanelElement.appendTo(this.appendToElement);
            $.isFunction(this.options.onCreate) && this.options.onCreate.call(this);
        },
        /**
         * 创建日期选择列表
         * @param date{Date} 有效的日期字符或日期对象
         * @return object
         */
        _createSelectList: function(date) {
            var
            _date = calendar.changeDate(date),
                _data = calendar.getMonthTable(_date),
                _length = _data.length,
                _month = _date.getMonth() + 1,
                _week = [0, 6],
                _appendTo = null,
                _panel = '';
            _panel += '<table>';
            _panel += '<thead>';
            _panel += '<tr>';
            for (var i = 0; i < this.options.lang.weeks.length; i++) {
                _panel += '<th>' + this.options.lang.weeks[i] + '</th>';
            }
            _panel += '</tr>';
            _panel += '</thead>';
            _panel += '<tbody></tbody>';
            _panel += '</table>';
            _panel = $(_panel);
            _appendTo = _panel.find('tbody');
            for (var i = 0; i < _length; i++) {
                if (!(i % 7)) {
                    var _tr = $('<tr></tr>').appendTo(_appendTo);
                }
                _data[i]['element'] = $('<td class="'+this._stylePrefix+'-date-day">' + _data[i]['day'] + '</td>');
                $.inArray(_data[i]['week'], _week) >= 0 && _data[i]['element'].addClass(''+this._stylePrefix+'-date-weekend');
                _data[i]['month'] != _month && _data[i]['element'].addClass(''+this._stylePrefix+'-date-othermonth');
                _data[i]['element'].appendTo(_tr);
                _data[i]['isSelected'] = false;
                _data[i]['isDisabled'] = false;
                $.isFunction(this.options.praseData) && this.options.praseData.call(this, _data[i]);
            }
            return {
                data: _data,
                panel: _panel
            };
        },
        /**
         * 新增操作按钮
         * @param data{Array||Object} 按钮信息数据
         * @return calendar
         */
        addButton: function(data) {
            var _self = this,
                _button = $.isArray(data) ? data : [data];
            if (!this.buttonListElement) {
                this.buttonListElement = $('<div class="'+this._stylePrefix+'-buttons"></div>').appendTo(this.dateMainElement);
            }
            var _length = this._buttons.length;
            for (var i = 0; i < _button.length; i++) {
                if (typeof _button[i] == 'string') {
                    for (var i = 0; i < _length; i++) {
                        if (this._buttons[i]['name'] == _button[i]) {
                            _button[i] = this._buttons[i];
                            break;
                        }
                    }
                }
                if ($.isPlainObject(_button[i]) && ('name' in _button[i]) && ('value' in _button[i]) && !this.hasButton(_button[i]['name'])) {
                    _button[i]['element'] = $('<span class="'+this._stylePrefix+'-button '+this._stylePrefix+'-' + _button[i]['name'] + '">' + _button[i]['value'] + '</span>');
                    _button[i]['element'].appendTo(this.buttonListElement);
                    $.isFunction(_button[i]['func']) && _button[i]['func'].call(_self, _self, _button[i]['element']);
                    this._buttonList.push(_button[i]);
                }
            }
            return this;
        },
        /**
         * 获取指定或获取所有按钮
         * @param name 按钮名称
         * @return element
         */
        getButton: function(name) {
            var _element = null;
            if (typeof name != 'undefined') {
                for (var i = 0; i < this._buttonList.length; i++) {
                    if (this._buttonList[i]['name'] == 'name') {
                        return this._buttonList[i]['element'];
                    }
                }
            } else {
                _element = [];
                for (var i = 0; i < this._buttonList.length; i++) {
                    _element.push(this._buttonList[i]['element']);
                }
            }
            return _element;
        },
        /**
         * 删除指定或删除所有按钮
         * @param name 按钮名称
         * @return calendar
         */
        delButton: function(name) {
            if (typeof name != 'undefined') {
                for (var i = 0; i < this._buttonList.length; i++) {
                    if (this._buttonList[i]['name'] == 'name') {
                        this._buttonList[i]['element'].remove();
                        this._buttonList.splice(i, 1);
                    }
                }
            } else {
                for (var i = 0; i < this._buttonList.length; i++) {
                    this._buttonList[i]['element'].remove();
                }
                this._buttonList = [];
            }
            return this;
        },
        /**
         * 检测是否存在按钮
         * @param name 按钮名称
         * @return calendar
         */
        hasButton: function(name) {
            for (var i = 0; i < this._buttonList.length; i++) {
                if (this._buttonList[i]['name'] == name) {
                    return true;
                }
            }
            return false;
        },
        /**
         * 将面板切换到指定日期
         * @param date{Date} 有效的日期字符或日期对象
         * @return calendar
         */
        targetDate: function(date) {
            var _currentDate = calendar.changeDate(date);
            if (!this._currentDate || calendar.formatDate(this._currentDate, 'YYYY-MM') != calendar.formatDate(_currentDate, 'YYYY-MM')) {
                var _selectData = this._createSelectList(_currentDate);
                this._selectPanel = _selectData.panel;
                this._selectData = _selectData.data;
                this._currentDate = _currentDate;
                this.dateOptionElement = this._selectPanel.find('.'+this._stylePrefix+'-date-day');
                this._switchPanel('date');
                this.dateSelectElement.html(this._selectPanel);
                $(this).trigger('onChange');
            }
            var _length = this._selectData.length;
            var _today = calendar.formatDate(new Date(), 'YYYY-MM-DD');
            for (var i = 0; i < _length; i++) {
                if (this._selectData[i]['date'] == _today) {
                    this.todayElement = this._selectData[i]['element'].addClass(this._stylePrefix+'-date-today');
                }
            }
            this.maxDate(this._maxDate);
            for (var i = 0; i < this._selectedDate.length; i++) {
                this._selected(this._selectedDate[i], true);
            }
            return this;
        },
        /**
         * 获取当前日期选择列表数据
         * @return array
         */
        getSelectDate: function() {
            var _data = [],
                _length = this._selectData.length;
            for (var i = 0; i < _length; i++) {
                _data.push(this._selectData[i]['date']);
            }
            return _data;
        },
        /**
         * 获取指定日期的选择项
         * @return array
         */
        getSelectItem: function(date) {
            var _length = this._selectData.length;
            for (var i = 0; i < _length; i++) {
                if (this._selectData[i]['date'] == date) {
                    return this._selectData[i]['element'];
                }
            }
        },
        /**
         * 切换或获取当前选择面板
         * @name {String} 面板的名称
         * @return calendar
         */
        _switchPanel: function(name) {
            var _self = this;
            if (typeof name != 'undefined') {
                if ($.inArray(name, ['date', 'month', 'year']) >= 0) {
                    this._currentPanel = name;
                    if (this._currentPanel == 'month') {
                        if (!this.monthSelect) {
                            this.monthSelect = new calendar.monthPicker({
                                style: this._stylePrefix+'-month',
                                currentMonth: this._currentDate,
                                switchPanel: false,
                                appendTo: this.dateWrapElement,
                                onChange: function() {
                                    _self._currentDate.setFullYear(this.getPanelYear());
                                },
                                onSelect: function() {
                                    _self.targetDate(this.selected());
                                }
                            });
                        }
                        this.monthSelect.selected(this._currentDate);
                        this.datePanelElement.addClass(this._stylePrefix+'-month-active').removeClass(this._stylePrefix+'-year-active '+this._stylePrefix+'-date-active');
                    } else if (this._currentPanel == 'year') {
                        if (!this.yearSelect) {
                            this.yearSelect = new calendar.yearPicker({
                                style: this._stylePrefix+'-year',
                                currentYear: this._currentDate,
                                switchPanel: false,
                                appendTo: this.dateWrapElement,
                                onSelect: function() {
                                    _self._switchPanel('month');
                                }
                            });
                        }
                        this.yearSelect.selected(this._currentDate);
                        this.datePanelElement.addClass(this._stylePrefix+'-year-active').removeClass(this._stylePrefix+'-month-active '+this._stylePrefix+'-date-active');
                    } else {
                        this.datePanelElement.addClass(this._stylePrefix+'-date-active').removeClass(this._stylePrefix+'-month-active '+this._stylePrefix+'-year-active');
                    }
                    this._updatePanelValue();
                }
            } else {
                return this._currentPanel;
            }
        },
        /**
         * 设置或取消或返回是否固定选择
         * @param status 选择状态
         * @return calendar
         */
        fixedType: function(status) {
            if (typeof status != 'undefined') {
                this._isFixed = status ? true : false;
                if (this._isFixed) {
                    this.switchHander.disabled(0, true);
                    this.switchHander.disabled(1, true);
                    this.switchHander.disabled(2, true);
                } else {
                    this.switchHander.disabled(0, false);
                    this.switchHander.disabled(1, false);
                    this.switchHander.disabled(2, false);
                }
            } else {
                return this._isFixed;
            }
            return this;
        },
        /**
         * 更新当前面板显示值
         * @param action 面板切换的动作标识
         * @return calendar
         */
        _updatePanelValue: function(action) {
            var _value = '',
                _status = $.type(action) == 'string';
            if (this._currentPanel == 'date') {
                _status && this[action + 'Month']();
                _value = calendar.formatDate(this._currentDate, 'YYYY年MM月');
            } else if (this._currentPanel == 'month') {
                _status && this.monthSelect[action + 'Year']();
                _value = this.monthSelect.getPanelYear() + '年';
            } else if (this._currentPanel == 'year') {
                _status && this.yearSelect[action + 'Range']();
                var _range = this.yearSelect.getSelectRange();
                _value = _range[1] + '-' + _range[_range.length - 2];
            }
            this.switchHander.value(_value);
            return this;
        },
        /**
         * 设置或返回是否多选
         * @param status 多选状态
         * @return calendar
         */
        multiple: function(status) {
            if (typeof status != 'undefined') {
                this._isMultiple = status ? true : false;
            } else {
                return this._isMultiple;
            }
            return this;
        },
        /**
         * 返回控件是否多选
         * @return boolean
         */
        isMultiple: function() {
            return this._isMultiple;
        },
        /**
         * 返回并选中今天
         * @return calendar
         */
        today: function() {
            var _today = new Date();
            if (this.multiple()) {
                var _selected = this._selectedDate,
                    _length = _selected.length;
                for (var i = 0; i < _length; i++) {
                    this._selected(_selected[i], false);
                }
            }
            this.targetDate(_today);
            this.selected(_today);
            return this;
        },
        /**
         * 清除选中值
         * @return calendar
         */
        clear: function() {
            this._selected(this.selected(), false);
            $(this).trigger('onClear');
            return this;
        },
        /**
         * 设置或取消或返回选中日期
         * @param date{Date} 有效的日期字符或日期对象
         * @return calendar
         */
        _selected: function(date, status, callback) {
            if (typeof date != 'undefined') {
                var _date = calendar.formatDate(calendar.changeDate(date), 'YYYY-MM-DD');
                var _status = typeof status == 'undefined' ? true : status ? true : false;
                var _currentDate = calendar.formatDate(this._currentDate, 'YYYY-MM');
                if ((this._isFixed && _date.indexOf(_currentDate) < 0) || this.isDisabled(_date)) {
                    return false;
                }
                var _index = $.inArray(_date, this._selectedDate);
                if (_index >= 0) {
                    if (!_status) {
                        this._selectedDate.splice(_index, 1);
                    }
                } else {
                    if (_status) {
                        if (!this._isMultiple) {
                            this._selectedDate = [_date];
                        } else {
                            this._selectedDate.push(_date);
                        }
                    }
                }
                for (var i = 0; i < this._selectData.length; i++) {
                    if (this._selectData[i]['date'] == _date) {
                        if (_status) {
                            this._selectData[i]['element'].addClass(this._stylePrefix+'-date-selected');
                            this._selectData[i]['isSelected'] = true;
                        } else {
                            this._selectData[i]['element'].removeClass(this._stylePrefix+'-date-selected');
                            this._selectData[i]['isSelected'] = false;
                        }
                    } else {
                        if (!this._isMultiple) {
                            this._selectData[i]['element'].removeClass(this._stylePrefix+'-date-selected');
                            this._selectData[i]['isSelected'] = false;
                        }
                    }
                }
                $.isFunction(callback) && callback.call(this);
            } else {
                if (this._isMultiple) {
                    return this._selectedDate.concat([]);
                } else {
                    return this._selectedDate[0];
                }
            }
            return this;
        },
        /**
         * 设置或返回选中日期
         * @param date{Date} 有效的日期字符或日期对象
         * @return calendar
         */
        selected: function(date, status) {
            return this._selected(date, status, function() {
                this._isFixed || this.targetDate($.isArray(date) ? date[0] : date);
                $(this).trigger('onSelect', [date]);
            });
        },
        /**
         * 判断指定日期是否选中
         * @param date{Date} 有效的日期字符或日期对象
         * @return calendar
         */
        isSelected: function(date) {
            return $.inArray(date, this._selectedDate) >= 0 ? true : false;
        },
        /**
         * 切换到上月
         * @return calendar
         */
        prevMonth: function() {
            var _cloneDate = new Date(this._currentDate.getTime());
            var _prevDate = _cloneDate.setMonth(_cloneDate.getMonth() - 1);
            return this.targetDate(_prevDate);
        },
        /**
         * 切换到下月
         * @return calendar
         */
        nextMonth: function() {
            var _cloneDate = new Date(this._currentDate.getTime());
            var _nextDate = _cloneDate.setMonth(_cloneDate.getMonth() + 1);
            return this.targetDate(_nextDate);
        },
        /**
         * 显示或隐藏时间操作面板
         * @param status {Boolean} 显示或隐藏状态
         * @return calendar
         */
        showTime: function(status) {
            if (typeof status != 'undefined') {
                this._showTime = status ? true : false;
                if (this._showTime) {
                    this.time = new calendar.timePicker(new Date(this.origDate.getTime()), {
                        style: this._stylePrefix+'-time!',
                        appendTo: this.dateMainElement
                    });
                } else {
                    this.time && this.time.destroy();
                }
            } else {
                return this._showTime;
            }
            return this;
        },
        /**
         * 设置或获取最大日期值
         * @param date {Date} 最大取值范围
         * @return maxDate
         */
        maxDate: function(date) {
            if (typeof date != 'undefined') {
                var _maxTime = null,
                    _disabledDate = [];
                if (date) {
                    this._maxDate = calendar.changeDate(date);
                    _maxTime = this._maxDate.getTime();
                } else {
                    this._maxDate = null;
                }
                if (this._maxDate) {
                    for (var i = 0; i < this._selectData.length; i++) {
                        if (this._selectData[i]['time'] >= _maxTime) {
                            _disabledDate.push(this._selectData[i]['date']);
                        }
                    }
                    this.disabledDate(_disabledDate, true);
                } else {
                    this.disabledDate(this._disabledDate, false);
                }
            } else {
                return this._maxDate;
            }
            return this;
        },
        /**
         * 设置或获取最小日期值
         * @param date {Date} 最小取值范围
         * @return minDate
         */
        minDate: function(date) {

        },
        /**
         * 设置或获取无效的日期
         * @param date {Date} 无效的日期
         * @param satatus {Boolean}
         * @return minDate
         */
        invalidDate: function(date) {

        },
        /**
         * 设置日期是否禁用
         * @param date {Date} 指定日期
         * @param satatus {Boolean}
         * @return calendar
         */
        disabledDate: function(date, status) {
            if (typeof date != 'undefined') {
                var _date = $.isArray(date) ? date : [date];
                var _status = typeof status == 'undefined' ? true : status ? true : false;
                for (var i = 0; i < _date.length; i++) {
                    var _d = calendar.formatDate(calendar.changeDate(_date[i]), 'YYYY-MM-DD');
                    var _index = $.inArray(_d, this._disabledDate);
                    if (_index < 0) {
                        if (_status) {
                            this._disabledDate.push(_d);
                        }
                    } else {
                        if (!_status) {
                            this._disabledDate.splice(_index, 1);
                        }
                    }
                }
                for (var i = 0; i < this._selectData.length; i++) {
                    if ($.inArray(this._selectData[i]['date'], this._disabledDate) >= 0) {
                        this._selectData[i]['isDisabled'] = true;
                        this._selectData[i]['element'].addClass(this._stylePrefix+'-date-disabled');

                    } else {
                        this._selectData[i]['isDisabled'] = false;
                        this._selectData[i]['element'].removeClass(this._stylePrefix+'-date-disabled');
                    }
                }
            } else {
                return this._disabledDate;
            }
            return this;
        },
        /**
         * 检测指定日期是否被禁用
         * @param date {Date} 指定日期
         * @return Boolean
         */
        isDisabled: function(date) {
            if (typeof date != 'undefined') {
                var _date = calendar.formatDate(calendar.changeDate(date), 'YYYY-MM-DD');
                if ($.inArray(date, this._disabledDate) >= 0) {
                    return true;
                }
            }
            return false;
        },
        /**
         * 设置或获取启用的日期
         * @param date {Date} 无效的日期
         * @param satatus {Boolean}
         * @return minDate
         */
        enableDate: function(date) {

        },
        /**
         * 复位
         * @summary 复位到初始状态
         * @return calendar
         */
        reset: function() {

        },
        /**
         * 绑定事件
         * @summary 复位到初始状态
         * @return calendar
         */
        on: function(name, fun) {
            $(this).bind(name, fun);
            return this;
        },
        /**
         * 卸载事件
         * @summary 复位到初始状态
         * @return calendar
         */
        off: function(name) {
            $(this).unbind(name, fun);
            return this;
        }
    });
    //选择时间构造类
    calendar.timePicker = extend({
        _options: {
            style: 'think-timepicker',
            currentDate: new Date(),
            maxTime: null,
            minTime: null,
            invalidTime: null,
            appendTo: 'body',
            onChange: null
        },
        initial: function(time, options) {
            //合并配置
            this.options = $.extend({}, this._options, options);
            //记录样式名称
            this._styleName = calendar.getClass(this._options.style, this.options.style);
            //记录样式名前缀
            this._stylePrefix = this._styleName.split(' ')[0];
            //创建时间面板元素
            this.timePanelElement = $(this._createHtml());
            //绑定样式名称
            this.timePanelElement.addClass(this._styleName);
            //记录时间面板元素追加到指定的容器元素
            this.appendToElement = $(this.options.appendTo);
            //创建时间选择元素
            this.hourElement = this.timePanelElement.find('.'+this._stylePrefix+'-hour');
            //时间选择元素绑定微调控件
            this.hourSpinner = new calendar.spinner(this.hourElement, {
                style: this._stylePrefix+'-spinner!',
                maxValue: 23,
                minValue: 0,
                zerofill: true,
                increment: 1,
                places: 0
            });
            //创建分钟选择元素
            this.minuteElement = this.timePanelElement.find('.'+this._stylePrefix+'-minute');
            //分钟选择元素绑定微调控件
            this.minuteSpinner = new calendar.spinner(this.minuteElement, {
                style: this._stylePrefix+'-spinner!',
                maxValue: 59,
                minValue: 0,
                zerofill: true,
                increment: 1,
                places: 0
            });
            //创建秒钟选择元素
            this.secondElement = this.timePanelElement.find('.'+this._stylePrefix+'-second');
            //秒钟选择元素绑定微调控件
            this.secondSpinner = new calendar.spinner(this.secondElement, {
                style: this._stylePrefix+'-spinner!',
                maxValue: 59,
                minValue: 0,
                zerofill: true,
                increment: 1,
                places: 0
            });
            //记录原始时间
            this._origTime = this.options.currentDate;
            //初始设置时间
            this.time(this._origTime);
            //将时间面板元素添加到指定容器中
            this.timePanelElement.appendTo(this.appendToElement);
        },
        /**
         * 设置或获取小时
         * @value {Number} 小时值
         * @return time
         */
        hour: function(value) {
            if (typeof time != 'undefined') {
                if ($.isNumeric(value)) {
                    this._nowTime.hour = parseInt(value);
                    this.hourSpinner.value(this._nowTime.hour);
                }
            } else {
                return this._nowTime.hour;
            }
            return this;
        },
        /**
         * 设置或获取分钟
         * @value {Number} 分钟值
         * @return time
         */
        minute: function(value) {
            if (typeof time != 'undefined') {
                if ($.isNumeric(value)) {
                    this._nowTime.minute = parseInt(value);
                    this.minuteSpinner.value(this._nowTime.minute);
                }
            } else {
                return this._nowTime.minute;
            }
            return this;
        },
        /**
         * 设置或获取秒钟
         * @value {Number} 秒钟值
         * @return time
         */
        second: function(value) {
            if (typeof time != 'undefined') {
                if ($.isNumeric(value)) {
                    this._nowTime.second = parseInt(value);
                    this.secondSpinner.value(this._nowTime.second);
                }
            } else {
                return this._nowTime.second;
            }
            return this;
        },
        /**
         * 设置或获取时间
         * @return time
         */
        time: function(time) {
            if (typeof time != 'undefined') {
                this._nowTime = this._reviseTime(time);
                this.hourSpinner.value(this._nowTime.hour);
                this.minuteSpinner.value(this._nowTime.minute);
                this.secondSpinner.value(this._nowTime.second);
            } else {
                return this._nowTime;
            }
            return this;
        },
        /**
         * 禁止或激活选择
         * @status {Boolean} 状态
         * @return time
         */
        disabled: function(status) {
            if (typeof satatus != 'undefined') {
                this._disabled = satatus ? true : false;
                if (this._disabled) {
                    this.spinnerElement.addClass(this._stylePrefix+'-disabled');
                } else {
                    this.spinnerElement.removeClass(this._stylePrefix+'-disabled');
                }
                this.hourSpinner.disabled(this._disabled);
                this.minuteSpinner.disabled(this._disabled);
                this.secondSpinner.disabled(this._disabled);
            } else {
                return this._disabled;
            }
            return this;
        },
        /**
         * 销毁组件
         * @return void
         */
        destroy: function() {
            this.timePanelElement.remove();
            for (var i in this) {
                delete this[i];
            }
            return true;
        },
        /**
         * 创建元素
         * @return time
         */
        _createHtml: function() {
            return [
                '<div>',
                '<input class="'+this._stylePrefix+'-hour" type="text" maxlength="2"/>',
                '<span class="'+this._stylePrefix+'-split">:</span>',
                '<input class="'+this._stylePrefix+'-minute" type="text" maxlength="2"/>',
                '<span class="'+this._stylePrefix+'-split">:</span>',
                '<input class="'+this._stylePrefix+'-second" type="text" maxlength="2"/>',
                '</div>'
            ].join('');
        },
        /**
         * 解析时间
         * @return data
         */
        _reviseTime: function(time) {
            var _type = $.type(time),
                _date = time;
            if (_type != 'date') {
                if (_type == 'string') {
                    var _arr = _date.split(/\D/, 3);
                    _date = new Date();
                    _date.setHours($.isNumeric(_arr[0]) ? parseInt(_arr[0]) : 0);
                    _date.setMinutes($.isNumeric(_arr[1]) ? parseInt(_arr[1]) : 0);
                    _date.setSeconds($.isNumeric(_arr[2]) ? parseInt(_arr[2]) : 0);
                } else if (_type == 'number') {
                    _date = new Date(parseInt(_date));
                } else {
                    _date = new Date();
                }
            }
            _hour = _date.getHours();
            _minute = _date.getMinutes();
            _second = _date.getSeconds();
            return {
                hour: _hour,
                minute: _minute,
                second: _second
            }
        }
    });
    //微调组件类
    calendar.spinner = extend({
        _options: {
            style: 'think-spinner',
            value: null, //起始值
            maxValue: null, //最大值
            minValue: 0, //最小值
            invalidValue: null, //无效值
            increment: .5, //增量值
            zerofill: false, //小于10的时候值是否补零
            places: 2, //保留的小数点位数
            disabled: false, //是否禁用
            onZenga: null, //递增时触发事件函数
            onReduce: null, //递减时触发事件函数
            onChange: null, //值发生改变时触发
            onCreate: null //插件初始化后触发
        },
        initial: function(element, options) {
            var _self = this;
            //合并配置
            this.options = $.extend({}, this._options, options);
            //记录样式名称
            this._styleName = calendar.getClass(this._options.style, this.options.style);
            //记录样式名前缀
            this._stylePrefix = this._styleName.split(' ')[0];
            //记录原始值
            this._origValue = element.val() || this.options.value;
            //创建微调元素
            this.spinnerElement = $(this._createHtml()).addClass(this._styleName);
            //记录递增元素
            this.zengaElement = this.spinnerElement.find('.'+this._stylePrefix+'-zenga');
            //记录递减元素
            this.reduceElement = this.spinnerElement.find('.'+this._stylePrefix+'-reduce');
            //记录输入元素
            this.enterElement = element;
            //在输入元素后面插入微调元素
            this.enterElement.after(this.spinnerElement);
            //将输入元素添加到微调元素内
            this.enterElement.appendTo(this.spinnerElement.find('.'+this._stylePrefix+'-value'));
            //记录当前值
            this._currentValue = this.options.value;
            //设置最大输入值
            this.maxValue(this.options.maxValue);
            //设置最小输入值
            this.minValue(this.options.minValue);
            //设置输入增量值
            this.increment(this.options.increment);
            //设置保留小数位
            this.places(this.options.places);
            //设置当前值
            this._value(this.options.value);
            //设置是否禁用
            this.disabled(this.options.disabled);
            //速度加载器
            var _timer = null;
            var _speed = function(callback) {
                var _speed = 280;
                var _func = function() {
                    (_speed -= 40) < 40 && (_speed = 40);
                    _timer = setTimeout(_func, _speed);
                    $.isFunction(callback) && callback(_timer);
                }
                _func();
                return _timer;
            }
            //绑定递增事件
            this.zengaElement.bind('mousedown', function() {
                _speed(function(timer) {
                    _self.zenga();
                });
            });
            //绑定递减事件
            this.reduceElement.bind('mousedown', function() {
                _speed(function(timer) {
                    _self.reduce();
                });
            });
            this.zengaElement.add(this.reduceElement).bind('mouseup', function() {
                clearTimeout(_timer);
            });
            //绑定限制输入操作
            this.enterElement.bind('blur', function(event) {
                return _self.value($(this).val());
            });
            $.isFunction(this.options.onCreate) && this.options.onCreate.call(this);
        },
        /**
         * 设置或获取最大值
         * @number {Number} 最大值
         * @return spinner
         */
        maxValue: function(number) {
            if (typeof number != 'undefined') {
                this._maxValue = $.isNumeric(number) ? number : null;
                this._value(this._currentValue);
            } else {
                return this._maxValue;
            }
            return this;
        },
        /**
         * 设置或获取最小值
         * @number {Number} 最小值
         * @return spinner
         */
        minValue: function(number) {
            if (typeof number != 'undefined') {
                this._minValue = $.isNumeric(number) ? number : null;
                this._value(this._currentValue);
            } else {
                return this._minValue;
            }
            return this;
        },
        /**
         * 设置或获取当前值
         * @value {value} 当前值
         * @return spinner
         */
        value: function(number) {
            if (!this._disabled) {
                var _return = this._value(number);
                $.isFunction(this.options.onChange) && this.options.onChange.call(this);
                return _return;
            }
            return this;
        },
        /**
         * 设置或获取增量值
         * @value {value} 增量值
         * @return spinner
         */
        increment: function(number) {
            if (typeof number != 'undefined') {
                this._increment = $.isNumeric(number) ? number : 1;
            } else {
                return this._increment;
            }
            return this;
        },
        /**
         * 设置或获取保留小数位数
         * @value {value} 位数
         * @return spinner
         */
        places: function(number) {
            if (typeof number != 'undefined') {
                this._places = $.isNumeric(number) ? number : 0;
                this._value(this._currentValue);
            } else {
                return this._places;
            }
            return this;
        },
        /**
         * 设置或获取是否禁用
         * @value {value} 位数
         * @return spinner
         */
        disabled: function(satatus) {
            if (typeof satatus != 'undefined') {
                this._disabled = satatus ? true : false;
                if (this._disabled) {
                    this.spinnerElement.addClass(this._stylePrefix+'-disabled');
                } else {
                    this.spinnerElement.removeClass(this._stylePrefix+'-disabled');
                }
            } else {
                return this._disabled;
            }
            return this;
        },
        /**
         * 将当前值递增
         * @return spinner
         */
        zenga: function() {
            return this.value($.isNumeric(this._currentValue) ? Number(this._currentValue) + this._increment : this._increment);
        },
        /**
         * 将当前值递减
         * @return spinner
         */
        reduce: function() {
            return this.value($.isNumeric(this._currentValue) ? Number(this._currentValue) - this._increment : 0);
        },
        /**
         * 重置值
         * @return spinner
         */
        reset: function() {
            return this.value(this._origValue);
        },
        /**
         * 设置或返回当前值
         * @number {Number} 当前值
         * @return spinner
         */
        _value: function(number) {
            if (typeof number != 'undefined') {
                if ($.isNumeric(number) || !number) {
                    number = Number(number).toFixed(this._places);
                } else {
                    number = this._currentValue;
                }
                if (number != '') {
                    if (number > this._maxValue) {
                        number = this._maxValue;
                    } else if (number < this._minValue) {
                        number = this._minValue;
                    }
                    this.options.zerofill && number < 9 && (number = '0' + number);
                }
                this.enterElement.val(number);
                this._currentValue = number;
            } else {
                return this._currentValue;
            }
            return this;
        },
        /**
         * 创建元素
         * @return spinner
         */
        _createHtml: function() {
            return [
                '<span>',
                '<span class="'+this._stylePrefix+'-value"></span>',
                '<span class="'+this._stylePrefix+'-control">',
                '<b class="'+this._stylePrefix+'-zenga"><i class="'+this._stylePrefix+'-block">+</i></b>',
                '<b class="'+this._stylePrefix+'-reduce"><i class="'+this._stylePrefix+'-block">-</i></b>',
                '</span>',
                '</span>'
            ].join('')
        }
    });
    /**
     * 返回样式名称
     * @return string
     */
    calendar.getClass = function(style1, style2) {
        var _class = [];
        for (var i = 0; i < arguments.length; i++) {
            if (typeof arguments[i] == 'string') {
                var _index = arguments[i].lastIndexOf('!');
                if (_index == arguments[i].length - 1) {
                    _class = [arguments[i].substr(0, _index)];
                    break;
                } else {
                    _class.push(arguments[i]);
                }
            }
        }
        return _class.join(' ');
    }
    /**
     * 获取当天的时间戳
     * @return time
     */
    calendar.getTodayTime = function() {
        var _date = new Date(),
            _year = _date.getFullYear(),
            _month = _date.getMonth(),
            _date = _date.getDate();
        return new Date(_year, _month, _date).getTime();
    }
    /**
     * 获取指定日期的所在月份的数据表
     * @param date {Date} 日期对象
     * @return Array
     */
    calendar.getMonthTable = function(date) {
        var
        _year = 0,
            _month = 0,
            _day = 0,
            _step = 0,
            _data = [],
            _date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
        _date.setDate(1);
        _date.setDate(1 - _date.getDay());
        for (var i = 0; i < 42; i++) {
            _date.setDate(_date.getDate() + _step);
            _step = 1;
            _year = _date.getFullYear();
            _month = _date.getMonth() + 1;
            _day = _date.getDate();
            _data.push({
                year: _year,
                month: _month,
                day: _day,
                date: _year + '-' + (_month < 10 ? '0' + _month : _month) + '-' + (_day < 10 ? '0' + _day : _day),
                week: _date.getDay(),
                time: _date.getTime()
            });
        }
        return _data;
    }
    /**
     * 将日期字符串转换为日期对象
     * @param date {String} 日期字符串
     * @return Array
     */
    calendar.changeDate = function(date) {
        if ($.type(date) != 'date') {
            var _currentDate = new Date();
            if (date) {
                if ($.isNumeric(date)) {
                    _currentDate.setTime(parseInt(date));
                } else {
                    date = date.toString();
                    date = date.match(/([0-9]+)/g);
                    if (date) {
                        var _year = parseInt(date[0]) || 0;
                        var _month = parseInt(date[1]) - 1 || 0;
                        var _date = parseInt(date[2]) || 1;
                        var _hour = parseInt(date[3]) || 0;
                        var _minute = parseInt(date[4]) || 0;
                        var _second = parseInt(date[5]) || 0;
                        _currentDate = new Date(_year, _month, _date, _hour, _minute, _second);
                    }
                }
            }
            return _currentDate;
        }
        return date;
    }
    /**
     * 格式化日期
     * @param date {String|Date} 日期字符串
     * @param format {YYYY-MM-DD} 格式化方式
     * @return Array
     */
    calendar.formatDate = function(date, format) {
        var _date = date;
        if (typeof _date == 'string') {
            var _arr = _date.split(/\D/);
            var _date = new Date(_arr[0], _arr[1] - 1, _arr[2], _arr[3], _arr[4], _arr[5]);
        }
        var o = {
            "M+": _date.getMonth() + 1,
            "D+": _date.getDate(),
            "h+": _date.getHours(),
            "m+": _date.getMinutes(),
            "s+": _date.getSeconds(),
            "q+": Math.floor((_date.getMonth() + 3) / 3),
            "S": _date.getMilliseconds()
        };
        if (/(Y+)/.test(format)) {
            format = format.replace(RegExp.$1, (_date.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }
    $.calendar = function(options) {
        return new calendar(options);
    }
    $.calendar.getMonthTable = calendar.getMonthTable;
    $.calendar.changeDate = calendar.changeDate;
    $.calendar.formatDate = calendar.formatDate;
})(jQuery);
